home *** CD-ROM | disk | FTP | other *** search
- Path: news.belwue.de!uzwil!kuehl
- From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
- Newsgroups: comp.lang.c++
- Subject: Re: main()
- Date: 18 Apr 1996 13:44:23 GMT
- Organization: FakultΣt fⁿr Mathematik und Informatik
- Message-ID: <4l5gvn$scp@news.BelWue.DE>
- References: <3174c0dc.7652220@news.flex.com.au> <829766541snz@j-bg.demon.co.uk> <Dq1C8B.3sC@news.hawaii.edu>
- Reply-To: dietmar.kuehl@uni-konstanz.de
- NNTP-Posting-Host: uzwil.informatik.uni-konstanz.de
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hi,
- Alvin Nonaka (xea0005@co.honolulu.hi.us) wrote:
- : I believe the authors intended to say:
-
- I believe that an author who intended to say what you said has no clue
- about portable programming.
-
- : #include <stdio.h>
- : #include <stdlib.h>
- : void main(void)
-
- There are only two portable declarations of 'main' in C and C++:
-
- int main()
- int main(int ac, char *av[])
-
- The version you suggested is not included in the list of portable
- declarations. By "portable declaration" I mean a declaration which has
- to be supported by a standard conforming compiler.
-
- : {
- : printf("Hello!\n");
- : exit(0);
- : }
-
- : 'main' can't return. Calling 'exit' is better because the call to exit
- : 'cleans up' all resource allocations (which you are supposed to handle)
- : left pending in your code.
-
- Given the portable declarations of 'main', it can return. In particular
- it can return one of the two values 'EXIT_SUCCESS' (which is guaranteed
- to be '0'), indicating a successful run of the program to the
- environment, and 'EXIT_FAILURE' indicating a failed run of the program
- (note that there is no portable value other than 'EXIT_FAILURE' to
- indicate failure). Both values are declared in '<stdlib.h>' (C) or
- '<cstdlib>' (C++). The definition of returning from 'main' is to call
- (guess what) 'exit'. Thus, I don't see why it should be any better to
- call 'exit' instead of returning from 'main'.
- --
- dietmar.kuehl@uni-konstanz.de
- http://www.informatik.uni-konstanz.de/~kuehl/
- I am a realistic optimist - that's why I appear to be slightly pessimistic
-